package com.rui.study.algorithm.P_合并两个有序数组;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-01-14 09:20
 **/
public class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] temp = new int[nums1.length];
        int p = 0, q = 0;
        for (int i = 0; i < temp.length; i++) {
            if (p < m && q < n) {
                if (nums1[p] < nums2[q]) {
                    temp[i] = nums1[p++];
                } else  {
                    temp[i] = nums2[q++];
                }
            } else if (p < m) {
                temp[i] = nums1[p++];
            } else if (q < n) {
                temp[i] = nums2[q++];
            }
        }

        for (int i = 0; i < temp.length; i++) {
            nums1[i] = temp[i];
        }
    }
}
